//
//  ByViewFastLocation.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/30.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewFastLocation.h"

@implementation ByViewFastLocation

- (instancetype)init {
    
    if (self = [super init]) {
        
    }
    return self;
}

- (void)setupUI {
    
    UILabel *lastLabel;
    for (int i = 0; i < _keys.count; i ++) {
        
        UILabel *label = [[UILabel alloc] init];
        label.userInteractionEnabled = true;
        label.text = _keys[i];
        label.font = FONT(14);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        label.tag = i;
        [self addSubview:label];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchAction:)];
        [label addGestureRecognizer:tap];
        
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            if (i == 0) {
                make.top.equalTo(@10);
            } else {
                make.top.equalTo(lastLabel.mas_bottom);
            }
            make.height.equalTo(@20);
            make.left.width.equalTo(self);
        }];
        
        lastLabel = label;
    }
}

- (void)setKeys:(NSArray *)keys {
    
    _keys = keys;
    
    [self setupUI];
}

- (void)touchAction:(UITapGestureRecognizer *)tap {

    UILabel *label = (UILabel *)tap.view;
    NSString *c = label.text;
    NSInteger tag = label.tag;
    if (self.fastLocationBlock) {
        self.fastLocationBlock(c, tag);
    }
}
@end
